package com.xnyzc.lhy.statistics.controller.summary;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.statistics.eenum.ECapacityOption;
import com.xnyzc.lhy.statistics.eenum.EOrderOption;
import com.xnyzc.lhy.statistics.entity.param.capacity.CapacityParam;
import com.xnyzc.lhy.statistics.service.capacity.OrderSummaryService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 运力统计
 *
 * @Author: wangshuo
 * @Date: 2019-11-28 14:11
 */
@RestController
@RequestMapping("/cmsapi/summary")
public class OrderSummaryController {

    @Autowired
    private OrderSummaryService orderSummaryService;

    /**
     * 获取实时订单数据
     * @return
     */
    @ApiOperation(value = "获取实时订单数据", notes = "获取实时订单数据")
    @PostMapping(value = "/getSummaryResult")
    public Rv getSummaryResult(
            @ApiParam(name = "capacityParam", value = "城市CODE") @RequestBody CapacityParam capacityParam
    ) {
        return orderSummaryService.getSummaryResult(capacityParam);
    }

    /**
     * 获取实时订单数据
     * @return
     */
    @ApiOperation(value = "获取实时订单柱状图", notes = "获取实时订单柱状图")
    @PostMapping(value = "/getSummaryStatistical")
    public Rv getSummaryStatistical(
            @ApiParam(name = "capacityParam", value = "城市CODE") @RequestBody CapacityParam capacityParam
    ) {
        return orderSummaryService.getSummaryStatistical(capacityParam);
    }

    /**
     * 获取订单折线集
     * @return
     */
    @ApiOperation(value = "获取订单折线集", notes = "获取订单折线集")
    @PostMapping(value = "/getHistorySummaryStatistical")
    public Rv getHistorySummaryStatistical(
            @ApiParam(name = "capacityParam", value = "折线集DTO") @RequestBody CapacityParam capacityParam
    ) {
        return orderSummaryService.getHistorySummaryStatistical(capacityParam);
    }

    /**
     * 获取运力数据趋势折线图Option
     * @return
     */
    @ApiOperation(value = "获取订单数据趋势折线图Option", notes = "获取订单数据趋势折线图Option")
    @GetMapping(value = "/getSummaryOption")
    public Rv getChartOption() {
        List<Map<String, Object>> capacityOptionList = new ArrayList<>();

        for (EOrderOption examine : EOrderOption.values()) {
            Map<String, Object> result = new HashMap<>(7);
            result.put("key", examine.getKey());
            result.put("value", examine.getValue());
            capacityOptionList.add(result);
        }

        return Rv.wrap(capacityOptionList);
    }

}
